cmake_minimum_required(VERSION 3.20 FATAL_ERROR)

list(APPEND CMAKE_MODULE_PATH
    "${CMAKE_CURRENT_SOURCE_DIR}/cmake/platforms"
    "${CMAKE_CURRENT_SOURCE_DIR}/cmake/projects"
)

include(config.cmake)

set(CMAKE_TOOLCHAIN_FILE arm-none-eabi-gcc)

set(CMAKE_COLOR_DIAGNOSTICS ON CACHE STRING "" FORCE)

project(at32
    LANGUAGES C ASM CXX
)

add_custom_target(print_compiler ALL
    COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --magenta -----------------------------------------------------------------------------
    COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --magenta "system = ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_PROCESSOR}"
    COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --magenta "config = $<IF:$<BOOL:$<CONFIG>>,$<CONFIG>,Debug Mode>"
    COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --magenta "toolchain execute process:"
    COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --magenta ${CMAKE_C_COMPILER}
    COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --magenta ${CMAKE_C_COMPILER}
    COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --magenta ${CMAKE_C_COMPILER}
    COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --magenta ${CMAKE_C_COMPILER}
    COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --magenta ${CMAKE_C_COMPILER}
    COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --magenta ${CMAKE_CXX_COMPILER}
    COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --magenta ${CMAKE_ASM_COMPILER}
    COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --magenta ${CMAKE_C_COMPILER_AR}
    COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --magenta ${CMAKE_LINKER}
    COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --magenta ${CMAKE_READELF}
    COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --magenta ${CMAKE_RANLIB}
    COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --magenta ${CMAKE_CXX_COMPILER_AR}
    COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --magenta ${CMAKE_C_COMPILER_TARGET}
    COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --magenta -----------------------------------------------------------------------------
)

add_compile_definitions(
    AT32F403AVGT7
    USE_STDPERIPH_DRIVER
    AT_WEACT_V10
)

# include(at32_create_projects.cmake)
include(at_start_f403a.library)
include(at_start_f403a.at32f403a_407_board)
include(at_start_f403a.examples.gpio.led_toggle)
